package business_opportunity

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common/constants"
	opptyPb "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/business_opportunity"
	pb "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service"
	"git.myscrm.cn/golang/stark/v4"
)

type strategicMonitorRepository struct {
}

func NewStrategicMonitorRepository() StrategicMonitorRepositoryIface {
	return &strategicMonitorRepository{}
}

func (r *strategicMonitorRepository) GetStrategicBidList(ctx context.Context, request *pb.GetStrategicBidListRequest) (*pb.GetStrategicBidListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetStrategicBidList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetStrategicBidList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetStrategicBidDetail(ctx context.Context, request *pb.GetStrategicBidDetailRequest) (*pb.GetStrategicBidDetailResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetStrategicBidDetail(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetStrategicBidDetail request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) AuditStrategicBid(ctx context.Context, request *pb.AuditStrategicBidRequest) (*pb.AuditStrategicBidResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.AuditStrategicBid(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AuditStrategicBid request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetBidCompanyList(ctx context.Context, request *pb.GetBidCompanyListRequest) (*pb.GetBidCompanyListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetBidCompanyList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetBidCompanyList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) AuditBidCompany(ctx context.Context, request *pb.AuditBidCompanyRequest) (*pb.AuditBidCompanyResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.AuditBidCompany(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AuditBidCompany request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) AddBidCompany(ctx context.Context, request *pb.AddBidCompanyRequest) (*pb.AddBidCompanyResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.AddBidCompany(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AuditStrategicBid request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetBidCompanyDetail(ctx context.Context, request *pb.GetBidCompanyDetailRequest) (*pb.GetBidCompanyDetailResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetBidCompanyDetail(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AuditStrategicBid request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetIndustryList(ctx context.Context, request *pb.GetIndustryListRequest) (*pb.GetIndustryListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetIndustryList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetIndustryList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) AuditIndustry(ctx context.Context, request *pb.AuditIndustryRequest) (*pb.AuditIndustryResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.AuditIndustry(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AuditIndustry request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) AddIndustry(ctx context.Context, request *pb.AddIndustryRequest) (*pb.AddIndustryResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.AddIndustry(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "AddIndustry request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetCompanyBidList(ctx context.Context, request *pb.GetCompanyBidListRequest) (*pb.GetCompanyBidListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetCompanyBidList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetCompanyBidList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetCompanyCooperateList(ctx context.Context, request *pb.GetCompanyCooperateListRequest) (*pb.GetCompanyCooperateListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetCompanyCooperateList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetCompanyCooperateList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) ImportCompanyBid(ctx context.Context, request *pb.ImportBidCompanyRequest) (*pb.ImportBidCompanyResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.ImportBidCompany(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "ImportCompanyBid request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) DeleteBidAudit(ctx context.Context, request *pb.DeleteBidAuditRequest) (*pb.DeleteBidAuditResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.DeleteBidAudit(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "DeleteBidAudit request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) DeleteCooperateCompany(ctx context.Context, request *pb.DeleteCooperateCompanyRequest) (*pb.DeleteCooperateCompanyResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := pb.NewStrategicMonitorServiceClient(conn)
	res, err := client.DeleteCooperateCompany(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "DeleteCooperateCompany request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) SubmitIndustry(ctx context.Context, request *opptyPb.SubmitIndustryRequest) (*opptyPb.SubmitIndustryResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.SubmitIndustry(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "SubmitIndustry request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetIndustryMonitorList(ctx context.Context, request *opptyPb.GetIndustryMonitorListRequest) (*opptyPb.GetIndustryMonitorListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetIndustryMonitorList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetIndustryMonitorList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetIndustrySubmitList(ctx context.Context, request *opptyPb.GetIndustrySubmitListRequest) (*opptyPb.GetIndustrySubmitListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetIndustrySubmitList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetIndustrySubmitList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) ChangeIndustryMonitorStatus(ctx context.Context, request *opptyPb.ChangeIndustryMonitorStatusRequest) (*opptyPb.ChangeIndustryMonitorStatusResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.ChangeIndustryMonitorStatus(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "ChangeIndustryMonitorStatus request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetIndustryStat(ctx context.Context, request *opptyPb.GetIndustryStatRequest) (*opptyPb.GetIndustryStatResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetIndustryStat(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetIndustryStat request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) SubmitCompany(ctx context.Context, request *opptyPb.SubmitCompanyRequest) (*opptyPb.SubmitCompanyResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.SubmitCompany(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "SubmitCompany request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetCompanyMonitorList(ctx context.Context, request *opptyPb.GetCompanyMonitorListRequest) (*opptyPb.GetCompanyMonitorListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetCompanyMonitorList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetCompanyMonitorList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetCompanySubmitList(ctx context.Context, request *opptyPb.GetCompanySubmitListRequest) (*opptyPb.GetCompanySubmitListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetCompanySubmitList(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetCompanySubmitList request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) ChangeCompanyMonitorStatus(ctx context.Context, request *opptyPb.ChangeCompanyMonitorStatusRequest) (*opptyPb.ChangeCompanyMonitorStatusResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.ChangeCompanyMonitorStatus(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "ChangeCompanyMonitorStatus request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}

func (r *strategicMonitorRepository) GetCompanyStat(ctx context.Context, request *opptyPb.GetCompanyStatRequest) (*opptyPb.GetCompanyStatResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetCompanyStat(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetCompanyStat request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}
func (r *strategicMonitorRepository) GetMonitorResult(ctx context.Context, request *opptyPb.GetMonitorResultRequest) (*opptyPb.GetMonitorResultResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := opptyPb.NewStrategicMonitorServiceClient(conn)
	res, err := client.GetMonitorResult(ctx, request)
	if err != nil {
		stark.Logger.Errorf(ctx, "GetMonitorResult request:%+v, err:%+v", request, err)
		return nil, err
	}
	return res, nil
}
